﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace ICAM
{
    public class DelegateCommand : ICommand
    {
        private Action<object> ExecuteCommand = null;
        private Func<object, bool> CanExecuteCommand = null;
        public event EventHandler CanExecuteChanged;
        public DelegateCommand(Action<object> ExecuteCommand)
        {
            this.ExecuteCommand = ExecuteCommand; 
        }

        public DelegateCommand(Action<object> ExecuteCommand, Func<object, bool> CanExecuteCommand)
        {
            this.ExecuteCommand = ExecuteCommand;
            this.CanExecuteCommand = CanExecuteCommand;
        }

        public bool CanExecute(object parameter)
        {
            if (CanExecuteCommand != null)
            {
                return this.CanExecuteCommand(parameter);
            }
            else
            {
                return true;
            }
        }

        public void Execute(object parameter)
        {
            if (this.ExecuteCommand != null)
            {
                this.ExecuteCommand(parameter);
            }
        }

        public void RaiseCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, EventArgs.Empty);
            }
        }
    }
}
